package com.xiaoma.myaudience.biz.task;

import java.util.Map;

import org.apache.http.Header;
import org.apache.http.message.BasicHeader;
import org.json.JSONObject;

import android.content.Context;

import com.xiaoma.myaudience.biz.model.RankingListModel;
import com.xiaoma.myaudience.biz.util.Constant;
import com.xiaoma.myaudience.util.HttpUtils;
import com.xiaoma.myaudience.util.Logger;
import com.xiaoma.myaudience.util.model.ModelUtils;
import com.xiaoma.myaudience.util.task.BaseDataAsyncTask;

/**
 * 评论Task
 * @author jpren
 *
 */
public class ReviewMoreListTask extends BaseDataAsyncTask<Map<String, String>, Void, Map<String, Object>>{
    private final static String TAG = "ReviewListTask";
    
    private boolean mIsPic;
    
    public ReviewMoreListTask(Context context, int taskType, DataAsyncCallback callback, boolean isPic) {
    	super(context, taskType, callback);
    	mIsPic = isPic;
    }
    
    public ReviewMoreListTask(Context context, int taskType, DataAsyncCallback callback) {
        super(context, taskType, callback);
    }


    @Override
    protected Map<String, Object> doInBackground(Map<String, String>... params) {  
    	Map<String, Object> result = null;
		Map<String, String> cookie = null;
		String type = "1";

    	String dateline = "0";
    	if (params != null) {
    		cookie = params[0];
    		dateline = cookie.get("dateline");
    		type = cookie.get(RankingListModel.PARAM_TYPE);
		}
        try {        
        	String cookiestr = Constant.LOGIN_COOKIE1+"="+cookie.get(Constant.LOGIN_COOKIE1)+";"+Constant.LOGIN_COOKIE2+"="+cookie.get(Constant.LOGIN_COOKIE2);
			Header[] headers = new BasicHeader[2];//("X-Online-Host",  format_CMWAP_ServerName(strPath));  
			headers[0]=new BasicHeader("Cookie", cookiestr);
			headers[1]=new BasicHeader("Accept-Language","zh-CN");
        	JSONObject jsonObject ;
        		String str = HttpUtils.getHttpStringResult(getHttpClient(), String.format(Constant.URL_REVIEW_MORE, type, dateline),
    					null, headers, HttpUtils.GET, "GBK");
        		jsonObject = new JSONObject(str);

        	if (jsonObject != null) {
        			Map<String, Object> objMap = ModelUtils.json2Map(jsonObject);
        			if (objMap != null) {
        				result = ModelUtils.getMapValue(objMap, RankingListModel.PARAM_DATA);
					}
				}
        } catch (Exception e) {
            Logger.e(TAG, "doInBackground error!!!", e);
        } finally {
            closeHttpClient();
        }
        
        return result;
    }
}
